package y2020.m03.d19;

public class XLSX {

    public static void main(String[] args) {
        System.out.println(getExcelColumnLetter(65));
        System.out.println(getExcelColumnLetter(66));
        System.out.println(getExcelColumnLetter(90));
        System.out.println(getExcelColumnLetter(91));
        System.out.println(getExcelColumnLetter(92));
        System.out.println(getExcelColumnLetter(100));
        System.out.println(getExcelColumnLetter(65 + 26 + 26));
    }

    public static String getExcelColumnLetter(int column) {
        column -= 64;
        StringBuilder columnLetter = new StringBuilder();
        while (column > 26) {
            int remainder = column % 26;
            if (0 == remainder) {
                columnLetter.insert(0, (char) (64 + 26));
                column = (column - 26) / 26;
            } else {
                columnLetter.insert(0, (char) (64 + remainder));
                column = (column - remainder) / 26;
            }
        }
        columnLetter.insert(0, (char) (64 + column));
        return columnLetter.toString();
    }
}


